<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="土地名称" prop="zoneName">
        <el-input
          v-model="queryParams.zoneName"
          placeholder="请输入土地名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="土地性质" prop="zoneXz">
        <el-input
          v-model="queryParams.zoneXz"
          placeholder="请输入土地性质"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="土地面积(亩)" prop="zoneArea">
        <el-input
          v-model="queryParams.zoneArea"
          placeholder="请输入土地面积(亩)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="土地性质" prop="zoneXz">
        <el-input
          v-model="queryParams.zoneXz"
          placeholder="请输入土地性质"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="地价(万/亩)" prop="zonePrice">
        <el-input
          v-model="queryParams.zonePrice"
          placeholder="请输入地价(万/亩)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经度" prop="zoneLongitude">
        <el-input
          v-model="queryParams.zoneLongitude"
          placeholder="请输入经度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="纬度" prop="zoneLatitude">
        <el-input
          v-model="queryParams.zoneLatitude"
          placeholder="请输入纬度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="行政区划" prop="zoneXzqh">
        <el-input
          v-model="queryParams.zoneXzqh"
          placeholder="请输入行政区划"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="地块地址" prop="zoneAddres">
        <el-input
          v-model="queryParams.zoneAddres"
          placeholder="请输入地块地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系人" prop="contactPerson">
        <el-input
          v-model="queryParams.contactPerson"
          placeholder="请输入联系人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系电话" prop="contactPhone">
        <el-input
          v-model="queryParams.contactPhone"
          placeholder="请输入联系电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最后修改时间" prop="modifiedTime">
        <el-date-picker clearable size="small"
          v-model="queryParams.modifiedTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择最后修改时间">
        </el-date-picker>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:zone:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:zone:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:zone:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:zone:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="zoneList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="地块ID" align="left" prop="zoneId" />
      <el-table-column label="土地名称" align="left" prop="zoneName" width="200" />
      <el-table-column label="土地面积(亩)" align="left" prop="zoneArea" width="200" />
      <el-table-column label="土地性质" align="left" prop="zoneXz" width="200" />
      <el-table-column label="地价(万/亩)" align="left" prop="zonePrice" width="200" />
      <el-table-column label="经度" align="left" prop="zoneLongitude" width="200" />
      <el-table-column label="纬度" align="left" prop="zoneLatitude" width="200" />
      <el-table-column label="行政区划" align="left" prop="zoneXzqh" width="200" />
      <el-table-column label="地块地址" align="left" prop="zoneAddres" width="200" show-overflow-tooltip  />
      <el-table-column label="联系人" align="left" prop="contactPerson" width="200" />
      <el-table-column label="联系电话" align="left" prop="contactPhone" width="200" />
      <el-table-column label="地块简介" align="left" prop="zoneIntro" width="200" show-overflow-tooltip  />
      <el-table-column label="最后修改时间" align="left" prop="modifiedTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.modifiedTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200" >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:zone:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:zone:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改地块属性信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="50%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="土地名称" prop="zoneName">
          <el-input v-model="form.zoneName" placeholder="请输入土地名称" />
        </el-form-item>
        <el-form-item label="土地面积(亩)" prop="zoneArea">
          <el-input v-model="form.zoneArea" placeholder="请输入土地面积(亩)" />
        </el-form-item>
        <el-form-item label="土地性质" prop="zoneXz">
          <el-input v-model="form.zoneXz" placeholder="请输入土地性质" />
        </el-form-item>
        <el-form-item label="地价(万/亩)" prop="zonePrice">
          <el-input v-model="form.zonePrice" placeholder="请输入地价(万/亩)" />
        </el-form-item>
        <el-form-item label="经度" prop="zoneLongitude">
          <el-input v-model="form.zoneLongitude" placeholder="请输入经度" />
        </el-form-item>
        <el-form-item label="纬度" prop="zoneLatitude">
          <el-input v-model="form.zoneLatitude" placeholder="请输入纬度" />
        </el-form-item>
        <el-form-item label="行政区划" prop="zoneXzqh">
          <el-input v-model="form.zoneXzqh" placeholder="请输入行政区划" />
        </el-form-item>
        <el-form-item label="地块地址" prop="zoneAddres">
          <el-input v-model="form.zoneAddres" placeholder="请输入地块地址" />
        </el-form-item>
        <el-form-item label="联系人" prop="contactPerson">
          <el-input v-model="form.contactPerson" placeholder="请输入联系人" />
        </el-form-item>
        <el-form-item label="联系电话" prop="contactPhone">
          <el-input v-model="form.contactPhone" placeholder="请输入联系电话" />
        </el-form-item>
        <el-form-item label="地块简介" prop="zoneIntro">
          <el-input v-model="form.zoneIntro"   :rows="4"
 type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="最后修改时间" prop="modifiedTime">
          <el-date-picker clearable size="small"
            v-model="form.modifiedTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择最后修改时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listZone, getZone, delZone, addZone, updateZone, exportZone } from "@/api/zsj/zone";

export default {
  name: "Zone",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 地块属性信息表格数据
      zoneList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        zoneName: null,
        zoneArea: null,
        zoneXz: null,
        zonePrice: null,
        zoneLongitude: null,
        zoneLatitude: null,
        zoneXzqh: null,
        zoneAddres: null,
        contactPerson: null,
        contactPhone: null,
        zoneIntro: null,
        modifiedTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询地块属性信息列表 */
    getList() {
      this.loading = true;
      listZone(this.queryParams).then(response => {
        this.zoneList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        zoneId: null,
        zoneName: null,
        zoneArea: null,
        zoneXz: null,
        zonePrice: null,
        zoneLongitude: null,
        zoneLatitude: null,
        zoneXzqh: null,
        zoneAddres: null,
        contactPerson: null,
        contactPhone: null,
        zoneIntro: null,
        modifiedTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.zoneId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加地块属性信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const zoneId = row.zoneId || this.ids
      getZone(zoneId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改地块属性信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.zoneId != null) {
            updateZone(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addZone(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const zoneIds = row.zoneId || this.ids;
      this.$confirm('是否确认删除地块属性信息编号为"' + zoneIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delZone(zoneIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有地块属性信息数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportZone(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
